from django.shortcuts import render
from rest_framework import viewsets
from rest_framework.views import APIView
from rest_framework.response import Response
from drf_spectacular.utils import extend_schema_view, extend_schema, OpenApiParameter
from .models import City
from .serializers import CitySerializer
from .pagination import CustomPagination

# Create your views here.
@extend_schema_view(
    list=extend_schema(
        summary='获取城市列表',  # 自定义接口摘要
        description='该接口返回所有城市的列表。',  # 自定义接口描述
        parameters=[
            OpenApiParameter(name='limit', type=int, description='每页显示的数量', required=False),
            OpenApiParameter(name='page', type=int, description='页码', required=False),
        ],
    ),
    retrieve=extend_schema(
        summary='获取城市详情',
        description='该接口根据城市 ID 返回城市的详细信息。',
    ),
    create=extend_schema(
        summary='创建城市',
        description='该接口用于创建新的城市。',
        request=CitySerializer
    ),
    update=extend_schema(
        summary='更新城市信息',
        description='该接口用于更新指定城市的信息。',
        request=CitySerializer,
    ),
    partial_update=extend_schema(
        summary='部分更新城市信息',
        description='该接口用于部分更新指定城市的信息。',
        request=CitySerializer,
    ),
    destroy=extend_schema(
        summary='删除城市',
        description='该接口用于删除指定的城市。',
    ),
)
@extend_schema(tags = ["城市管理接口"])
class CityViewSet(viewsets.ModelViewSet):
    """城市接口"""
    queryset = City.objects.all()
    serializer_class = CitySerializer
    pagination_class = CustomPagination  # 使用自定义分页器

